<?php
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use \Phalcon\Test\UnitTestCase as PhalconTestCase;

abstract class UnitTestCase extends PhalconTestCase
{

    /**
     * @var \Voice\Cache
     */
    protected $_cache;

    /**
     * @var \Phalcon\Config
     */
    protected $_config;

    /**
     * @var bool
     */
    private $_loaded = false;

    public function setUp(Phalcon\DiInterface $di = null, Phalcon\Config $config = null)
    {
        // Load any additional services that might be required during testing
        // $di = DI::getDefault();

        $di = new FactoryDefault();

        $config = include "../app/config/config.php";

        $di['db'] = function () use ($config) {
            $params = $config->db->mysql->toArray();
            return new \Phalcon\Db\Adapter\Pdo\Mysql($params);
        };

/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
        $di->set('modelsMetadata', function () {
            return new MetaDataAdapter();
        });
        $this->_loaded = true;

    }

    /**
     * Check if the test case is setup properly
     * @throws \PHPUnit_Framework_IncompleteTestError;
     */
    public function __destruct()
    {
        if (!$this->_loaded) {
            throw new \PHPUnit_Framework_IncompleteTestError('Please run parent::setUp().');

        }

    }

}
